<template>
  <div class="singerDetail" v-if="singerItem && songsList">
    <header>
      <van-icon name="arrow-left" size="18" @click="$router.back(-1)"/>
      <span @click="$router.back(-1)">返回</span>
    </header>
    <div class="singerinfo">
      <div class="bg">
        <img :src="singerItem.artist.cover" alt="" />
      </div>
      <div class="singerbox">
        <div class="info">
          <img :src="singerItem.artist.cover" alt="" />
          <h3>
            {{ singerItem.artist.name }}
            <img
              :src="singerItem.identify.imageUrl"
              alt=""
              v-if="singerItem.identify.imageUrl"
            />
          </h3>
          <p>{{ singerItem.identify.imageDesc }}</p>
        </div>
      </div>
    </div>
    <div class="tabs">
      <van-tabs v-model="activeName">
        <van-tab title="主页" name="主页">
          <div class="briefDesc">
            <h3>艺人介绍</h3>
            <p>{{ singerItem.artist.briefDesc }}</p>
          </div>
        </van-tab>
        <van-tab title="歌曲" name="歌曲">
          <div class="songs">
            <div class="title">
              <div>
                <van-icon name="play-circle" color="#9917f7" />
                <span>热门播放</span>
              </div>
              <van-button type="primary" 
              :round="true" 
              size="mini"
              @click="saveSheet"
                >播放全部</van-button
              >
            </div>
            <div class="list">
              <newsong-item
                v-for="item in songsList.songs"
                :key="item.id"
                :id="item.id"
              ></newsong-item>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script>
import newsongItem from "../components/newsongItem.vue";
import { getSingerDetail } from "../api/singer";
import {mapMutations} from "vuex"
export default {
  components: {
    newsongItem,
  },
  data() {
    return {
      singerItem: null,
      songsList: null,
      activeName: "主页",
    };
  },
  methods: {
    ...mapMutations(["xsavenowList"]),
    ...mapMutations(["xplaysong"]),
    saveSheet(){
      this.xsavenowList(this.songsList.songs)
      // console.log(this.sheetList.tracks);
      this.xplaysong(this.songsList.songs[0])
    }
  },
  created() {
    //获得歌手信息
    getSingerDetail(this.$route.query.id).info.then((res) => {
      this.singerItem = res.data;
    });
    //获得收受热曲
    getSingerDetail(this.$route.query.id).songs.then((res) => {
      this.songsList = res;
      console.log(this.songsList);
    });
  },

};
</script>

<style lang="scss" scoped>
.singerDetail {
  header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 50px;
    line-height: 50px;
    background-color: rgba(0, 0, 0, 0.1);
    color: #fff;
    z-index: 2;
    span {
      font-size: 18px;
    }
  }
  .singerinfo {
    position: relative;
    .bg {
      img {
        width: 100vw;
      }
    }
    .singerbox {
      width: 95vw;
      height: 150px;
      background-color: #fff;
      position: absolute;
      left: 50%;
      bottom: 0;
      transform: translateX(-50%) translateY(60px);
      z-index: 1;
      border-radius: 10px;
      box-shadow: 0 10px 10px #ccc;
      .info {
        text-align: center;
        margin-top: 10px;
        > img {
          width: 80px;
          height: 80px;
          border-radius: 50%;
        }
        h3 {
          font-size: 24px;

          > img {
            width: 20px;
          }
        }
        p {
          color: #bbb;
          font-size: 14px;
        }
      }
    }
  }
  .tabs {
    margin-top: 80px;
    .briefDesc {
      width: 95vw;
      margin: 20px auto;
      background-color: #fff;
      box-shadow: 5px 5px 5px #ccc;
      border-radius: 5px;
      padding: 10px;
      box-sizing: border-box;
      border: 1px solid #ccc;
      h3 {
        font-size: 20px;
        height: 40px;
        line-height: 40px;
      }
      p {
        font-size: 16px;
        text-indent: 2em;
        line-height: 30px;
      }
    }
    .songs {
      .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 10px;
        box-sizing: border-box;
        height: 50px;
        > span {
          font-size: 20px;
          font-weight: bold;
        }
      }
      .list {
      }
    }
  }
}
</style>